//
//  TitleHead.swift
//  HealthMonitoring
//
//  Created by 珠海正杰 on 2018/9/4.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

/// 每个药方的头部组件
class TitleHead: UIView {
    var id:Int?
    let colorView = UIView()
    let describe = UILabel()
    let value =  UILabel()
    let btn = UIButton()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
   
     convenience  init(_ target: Any?, addView: UIView?) {
        self.init(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 44))
        self.backgroundColor = UIColor.clear
        
        if addView != nil {
          self.addSubview(addView!)
        }
        setupViews(view: self)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //private
    func setupViews(view: UIView) {
        view.addSubview(colorView)
        view.addSubview(describe)
        
        colorView.centerYAlign(view: view)
        colorView.width(view: view, predicate: "*0.026")
        colorView.leadingAlign(view: view)
        colorView.height(view: view, predicate: "*0.8")
        colorView.backgroundColor = configure.shareConfigure.HMColor1
        
        describe.centerYAlign(view: view)
        describe.leadingHorizontally(view: colorView, predicate: "10")
        describe.width(view: view, predicate: "100")
        describe.height(view: view, predicate: "*0.6")
        describe.text = "适用病情: ---"
        
        view.addLayer(isAddLayer: (false, false, false, true), color: UIColor.gray, crude: 1, layout: nil)
//        view.addSubview(value)
        
    }
    
    func setJson(json: JSON) {
        let str = "适用病情: " + json["describe"].stringValue
        let attStr = NSMutableAttributedString.init(string: str) //NSRange(location:0, length: str.count)
        attStr.addAttributes([NSAttributedStringKey.foregroundColor: UIColor.orange], range: NSRange.init(location: 5, length: str.count - 5))
        self.describe.attributedText = attStr
    }
    
}
